package com.richman.controller;

import java.util.Iterator;
import java.util.Vector;

import com.richman.ps38.entity.SendData;

public class BetThread  extends Thread {
	
	public static Vector<String> betVec = new Vector<String>(); 
	public BetThread() {
		
	}
	
	public void removeBetVec(String betID) {
		Iterator<String> iterator = betVec.iterator();
        while (iterator.hasNext()) {
            String str = iterator.next();
            if (str.contains(betID)) {
                iterator.remove();
            }
        }
	}
	
	
	@Override
    public void run() {
		try {
			
			while(NegativeRatioClient.betCtrMng!=null&&NegativeRatioClient.bStartEngine==true) {
				try {
					Vector<SendData> sendDatas = NegativeRatioClient.betCtrMng.getSendData();
					if(sendDatas!=null) {
						for(int i = 0;  i< sendDatas.size(); i++) {
			        		SendData tmp = sendDatas.elementAt(i);
			        		
		        			String leaguename = tmp.isnps38event.leagueName;
		        			String teams = tmp.isnps38event.homeTeam + "-vs-" + tmp.isnps38event.awayTeam;
		        			String time = tmp.isnps38event.eventTime;
		        			String dxqPankouHalf = tmp.isnps38event.halfDXPPankou;
		        			String dxqPankouWhole = tmp.isnps38event.wholeDXPPankou;
		        			String score = tmp.isnps38event.homeTeamScore + ":" + tmp.isnps38event.awayTeamScore;
		        			
		        			String rqPankouWhole = tmp.isnps38event.wholeRQPPankou;
		        			String rqPankouHalf = tmp.isnps38event.halfRQPPankou;
		        			
		        			String betstrHalfDXQ = leaguename + teams + time + dxqPankouHalf + score;
		        			
		        			String betstrWholeDQ = leaguename + teams + time  + "全场大球|" + dxqPankouWhole + "|"  + score;
		        			
		        			String betstrWholeXQ = leaguename + teams + time  + "全场小球|" + dxqPankouWhole + "|"  + score;
		        			
//		        			String betstr_first = leaguename + teams + time  + "全场让球主|" + pankou + "|"  + score;
//		        			String betstr = betstr_first +   "|" + betodd + "|" + Integer.toString(betamount);
		        			
			    			String betstrWholeRQPHome = leaguename + teams + time + "全场让球主|" + rqPankouWhole+"|" + score ;
			    			String betstrWholeRQPAway = leaguename + teams + time + "全场让球客|" + rqPankouWhole+"|" + score ;
			    			
			    			String betstrHalfRQPHome = leaguename + teams + time + rqPankouHalf + score + "半场让球主";
			    			String betstrHalfRQPAway = leaguename + teams + time + rqPankouHalf + score + "半场让球客";
			    			
			    			for(int j = 0;j<betVec.size();j++) {
		    					String betstr = betVec.elementAt(j);
		    					if(betstr.contains(betstrWholeRQPHome)) {
		    						NegativeRatioClient.betCtrMng.autobetCtrMng.dobetgame("全场让球主", "2", tmp, betstr);
		    						break;
		    					}
		    				}
			    			
			    			for(int j = 0;j<betVec.size();j++) {
		    					String betstr = betVec.elementAt(j);
		    					if(betstr.contains(betstrWholeRQPAway)) {
		    						NegativeRatioClient.betCtrMng.autobetCtrMng.dobetgame("全场让球客", "2", tmp,betstr);
		    						break;
		    					}
		    				}
			    			
			    			for(int j = 0;j<betVec.size();j++) {
		    					String betstr = betVec.elementAt(j);
		    					if(betstr.contains(betstrWholeDQ)) {
		    						NegativeRatioClient.betCtrMng.autobetCtrMng.dobetgame("全场大小", "1", tmp,betstr);
		    						break;
		    					}
		    				}
			    			
			    			
			    			for(int j = 0;j<betVec.size();j++) {
		    					String betstr = betVec.elementAt(j);
		    					if(betstr.contains(betstrWholeXQ)) {
		    						NegativeRatioClient.betCtrMng.autobetCtrMng.dobetgame("全场大小", "2", tmp,betstr);
		    						break;
		    					}
		    				}
			    						    			
//			    			if(betVec.contains(betstrWholeDXQ+ "全场大小")) {
//			    				NegativeRatioClient.betCtrMng.autobetCtrMng.dobetgame("全场大小", "2", tmp,"");
//			    			}else if(betVec.contains(betstrHalfDXQ+ "半场大小")) {
//			    				NegativeRatioClient.betCtrMng.autobetCtrMng.dobetgame("半场大小", "2",  tmp,"");
//			    			}else if(betVec.contains(betstrWholeRQPHome)) {
//			    				for(int j = 0;j<betVec.size();j++) {
//			    					String betstr = betVec.elementAt(j);
//			    					if(betstr.contains(betstrWholeRQPHome)) {
//			    						NegativeRatioClient.betCtrMng.autobetCtrMng.dobetgame("全场让球主", "2", tmp, betstr);
//			    						break;
//			    					}
//			    				}
//			    				
//			    			}else if(betVec.contains(betstrWholeRQPAway)) {
//			    				for(int j = 0;j<betVec.size();j++) {
//			    					String betstr = betVec.elementAt(j);
//			    					if(betstr.contains(betstrWholeRQPAway)) {
//			    						NegativeRatioClient.betCtrMng.autobetCtrMng.dobetgame("全场让球客", "2", tmp,betstr);
//			    						break;
//			    					}
//			    				}
//			    			}else if(betVec.contains(betstrHalfRQPHome)) {
//			    				NegativeRatioClient.betCtrMng.autobetCtrMng.dobetgame("半场让球主", "2",  tmp,"");
//			    			}else if(betVec.contains(betstrHalfRQPAway)) {
//			    				NegativeRatioClient.betCtrMng.autobetCtrMng.dobetgame("半场让球客", "2",  tmp,"");
//			    			}	
			    			
						}
					}
					Thread.sleep(2000);
				}catch(Exception e) {
					e.printStackTrace();
				}
			}

		}catch(Exception e) {
			e.printStackTrace();
		}
		
		System.out.println("结束run");
	}
}